<?php

class ContactController extends Controller
{
    private $model;
    function __construct()
    {
        $this->loadLibrary('Utility');
        $this->loadLibrary('recaptcha');
                //(Utility::websiteRoot() . '/public/libraries/recaptcha.library.php');
        $this->model = $this->loadModel('contact');
        $this->loadModel('category',TRUE);
        $this->loadModel('ad',TRUE);
        parent::__construct();
    }

    public function index()
    {
        $rs['ad_list'] = $this->models['ad']->getAd();
        $cat_list = array();
        $this->models['category']->getCategories(0, $cat_list);        
        $data['cat_list'] = $cat_list;
        
        $data['current_page'] = 'contact';
        $view = $this->loadView('contact');
        $view->setBlockData($data,'menu');
        $view->setBlockData($rs,'adv');
        $view->setBlockData($data, 'cat_list');
        $view->setBlockData("Góp ý - liên hệ","title");
        $view->render();
    }

    public function send()
    {
        if (isset($_POST['name']))
        {
            $name = $_POST['name'];
            $email = $_POST['email'];
            $content = $_POST['content'];
            $message = $this->model->send($name, $email, $content);
        }
        $data['current_page'] = 'contact';
        $rs['ad_list'] = $this->models['ad']->getAd();
        $cat_list = array();
        $this->models['category']->getCategories(0, $cat_list);        
        $data['cat_list'] = $cat_list;
        $view = $this->loadView('contact');
        $view->setBlockData($data,'menu');
        $view->setBlockData($rs,'adv');
        $view->setBlockData($data, 'cat_list');
        $view->setBlockData('Liên hệ','title');
        if (isset($message)) $view->appendBlockData(array('message'=>$message));
        $view->render();
    }
}

